VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsScrollingBG"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'====================================================================================
'clsScrollingBackground - Create a smoothly scrolling background
'====================================================================================
Option Explicit

Public BGImage As New ImageDC   'The scrolling background image
Private ScrollX As Long         'Scrolling offset - horizontal
Private ScrollY As Long         'Scrolling offset - vertical
Public SpeedX As Long           'Speed of scrolling - horizontal
Public SpeedY As Long           'Speed of scrolling - vertical

'====================================================================================
'Initialize: Setup the scrolling background's attributes
'====================================================================================
Public Function Initialize(ByVal TilesetName As String, ByVal ScrollSpeedX As Long, ByVal ScrollSpeedY As Long)
    BGImage.CreateFromPicture LoadPicture(AppPath & "\gfx\Themes\" & TilesetName & "\BG.bmp")
    SpeedX = ScrollSpeedX
    SpeedY = ScrollSpeedY
End Function

'====================================================================================
'Animate: Scroll the background
'====================================================================================
Public Sub Animate()
    ScrollX = (ScrollX + SpeedX) Mod TileSize
    ScrollY = (ScrollY + SpeedY) Mod TileSize
End Sub

'====================================================================================
'Render: Draw the background
'====================================================================================
Public Sub Render(ByVal hDC As Long)
    Dim X As Long, Y As Long
    
    For Y = -1 To 7: For X = -1 To 10
        BGImage.Draw hDC, (X * TileSize) + ScrollX, (Y * TileSize) + ScrollY
    Next X: Next Y
End Sub

'====================================================================================
'CLASS Terminate: Free up memory when the class is destroyed
'====================================================================================
Private Sub Class_Terminate()
    'Erase graphics in memory
    Set BGImage = Nothing
End Sub

'=== END ============================================================================
'This work is licenced under the Creative Commons Attribution 2.5 License
